﻿package view.popup
{
    import base.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.text.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.roleN.model.*;
    import pluginfw.nio.*;

    public class NewOpenTitleUI extends View implements IDialogUI
    {
        public var closeBtn:Button;
        public var useBtn:Button;
        protected var uiXML:XML;
        private var _tiptxt:TextField;
        private var txt1:TextField;
        private var titleimg:Image;
        private var desTF:TextField;
        private var id:int;
        private var type:int = 0;
        private var _cfg:Object;

        public function NewOpenTitleUI()
        {
            this.uiXML = <View>r
n 	t	t	t  <Image url=""png.common.jinengbg"" x=""0"" y=""0"" width=""336"" height=""218"" sizeGrid=""70,30,70,40""/>r
n              <Button skin=""png.common.btn_cs2_bag"" x=""114"" y=""163"" labelStroke=""0x0"" var=""useBtn""/>	t	t r
n	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""304"" y=""8"" var=""closeBtn""/>r
n	t	t	t</View>")("<View>
 			  <Image url="png.common.jinengbg" x="0" y="0" width="336" height="218" sizeGrid="70,30,70,40"/>
              <Button skin="png.common.btn_cs2_bag" x="114" y="163" labelStroke="0x0" var="useBtn"/>		 
			  <Button skin="png.common.btn_cs2_close" x="304" y="8" var="closeBtn"/>
			</View>;
            this._cfg = ConfigDictionary.data.title;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        public function init() : void
        {
            this.visible = false;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 50;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            this._tiptxt = new TextField();
            this._tiptxt.x = 83;
            this._tiptxt.y = 10;
            this._tiptxt.width = 166;
            this._tiptxt.height = 25;
            this._tiptxt.defaultTextFormat = new TextFormat("宋体", 15, MColor.New16);
            this._tiptxt.autoSize = TextFieldAutoSize.CENTER;
            this._tiptxt.filters = [new GlowFilter(MColor.New12, 1, 2, 2, 2, BitmapFilterQuality.HIGH)];
            this._tiptxt.selectable = false;
            this.addChild(this._tiptxt);
            this.txt1 = new TextField();
            this.txt1.x = 63;
            this.txt1.y = 46;
            this.txt1.width = 206;
            this.txt1.height = 25;
            this.txt1.defaultTextFormat = new TextFormat("宋体", 15, MColor.New16);
            this.txt1.autoSize = TextFieldAutoSize.CENTER;
            this.txt1.selectable = false;
            this.addChild(this.txt1);
            this.titleimg = new Image();
            this.titleimg.y = 65;
            this.titleimg.x = 92 - 15;
            this.addChild(this.titleimg);
            this.useBtn.label = "使用";
            this.useBtn.labelColors = "0xb29a6c, 0xb29a6c, 0xb29a6c";
            this.useBtn.addEventListener(MouseEvent.CLICK, this.onSure);
            this.useBtn.x = int((336 - this.useBtn.width) * 0.5);
            this.desTF = new TextField();
            this.desTF.width = width - 60;
            this.desTF.height = 40;
            this.desTF.defaultTextFormat = new TextFormat("宋体", 12, 16775087);
            this.desTF.filters = [Common.BLACK_FILTER];
            this.desTF.selectable = false;
            this.desTF.y = 130;
            this.desTF.multiline = true;
            this.desTF.wordWrap = true;
            this.addChild(this.desTF);
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onSure(event:MouseEvent) : void
        {
            var _loc_2:Output = null;
            if (this.type == 0)
            {
                _loc_2 = new Output();
                _loc_2.writeVarInt(this.id, false);
                PluginManager.instance.sendToBufferServer("role", CMDRole.SetTitle, _loc_2);
            }
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_2:String = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Array = null;
            var _loc_6:String = null;
            this.type = 0;
            this.useBtn.label = "使用";
            this.titleimg.y = 65;
            this.desTF.y = 130;
            this.txt1.visible = false;
            this.desTF.visible = false;
            if (param1.hasOwnProperty("type") && param1.type)
            {
                this.id = int(param1.p);
                this.type = int(param1.type);
                this._tiptxt.text = "你的称号已被回收";
                this.txt1.visible = true;
                if (this.id == 0)
                {
                    return;
                }
                for each (_loc_3 in this._cfg)
                {
                    
                    if (int(_loc_3.id) == this.id)
                    {
                        _loc_2 = _loc_3.name;
                        break;
                    }
                }
                if (!_loc_2)
                {
                    return;
                }
                this.txt1.htmlText = "您的特殊称号：" + MColor.getHMTL(_loc_2 + "", 7) + "已经被回收";
                this.useBtn.label = "确定";
            }
            else
            {
                this.id = int(param1);
                _loc_4 = this._cfg[this.id];
                if (_loc_4)
                {
                    _loc_5 = _loc_4.desc.split("<br>");
                    switch(this.id)
                    {
                        case 1013:
                        {
                            this.titleimg.y = 65 - 9;
                            this.desTF.y = 130 - 9;
                        }
                        case 1014:
                        case 1017:
                        {
                            _loc_6 = _loc_5[0] + "：";
                            _loc_6 = _loc_6 + _loc_5.slice(1).join(",");
                            break;
                        }
                        case 1015:
                        {
                            _loc_6 = _loc_5.join(",");
                            break;
                        }
                        default:
                        {
                            _loc_6 = _loc_5.join("");
                            break;
                            break;
                        }
                    }
                    this.desTF.text = _loc_6;
                    this.desTF.x = int((width - this.desTF.textWidth) * 0.5);
                    this.desTF.visible = true;
                }
                this._tiptxt.text = "你获得了新的称号";
            }
            this.titleimg.url = Config.getUrl("assets/images/icon/title/" + this.id + ".png", ResourceType.NORMAL);
            this.visible = true;
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            this.visible = false;
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 50;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            return;
        }// end function

        private function openplugin(param1:String, param2:Object = null) : void
        {
            var _loc_3:* = UIGlobel.pointsDic[param1];
            if (_loc_3)
            {
                if (param2)
                {
                    PluginManager.instance.openPlugin(param1, new Point(_loc_3.x, _loc_3.y), param2);
                }
                else
                {
                    PluginManager.instance.openPlugin(param1, new Point(_loc_3.x, _loc_3.y));
                }
            }
            else if (param2)
            {
                PluginManager.instance.openPlugin(param1, new Point(100, 100), param2);
            }
            else
            {
                PluginManager.instance.openPlugin(param1, new Point(100, 100));
            }
            return;
        }// end function

    }
}
